package com.huike.report.service.impl;

import com.huike.business.mapper.TbBusinessMapper;
import com.huike.clues.domain.vo.IndexStatisticsVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbCourseMapper;
import com.huike.common.utils.SecurityUtils;
import com.huike.contract.mapper.TbContractMapper;
import com.huike.report.domain.vo.IndexVo;
import com.huike.report.service.IIndexService;
import com.huike.report.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class IndexServiceImpl implements IIndexService {

    @Autowired
    private IReportService reportService;

    @Autowired
    private TbClueMapper clueMapper;//查线索

    @Autowired
    private TbBusinessMapper businessMapper;//查商机

    @Autowired
    private TbContractMapper contractMapper;//查合同

    /**
     * 查询基础数据，今日数据，待办数据
     * @param beginCreatTime
     * @param endCreatetime
     * @return
     */
    @Override
    public IndexVo get(String beginCreatTime,String endCreatetime) {


        //取12个数据
        String username = SecurityUtils.getUsername();//先获取当前用户的用户名
        String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());//设置当前时间

        IndexVo indexVo =  new IndexVo();
        indexVo.setToallocatedCluesNum(clueMapper.getToallocatedCluesNum(beginCreatTime, endCreatetime, username));//待分配线索
        indexVo.setTofollowedCluesNum(clueMapper.getTofollowedCluesNum(beginCreatTime, endCreatetime, username));//待跟进线索
        indexVo.setToallocatedBusinessNum(businessMapper.getToallocatedBusinessNum(beginCreatTime, endCreatetime, username));//待分配商机
        indexVo.setTofollowedBusinessNum(businessMapper.getTofollowedBusinessNum(beginCreatTime, endCreatetime, username));//待分配商机
        indexVo.setTodayCluesNum(clueMapper.getTodayCluesNum(today, username));//今日线索数量
        indexVo.setTodayBusinessNum(businessMapper.getTodayBusinessNum(today, username));//今日商机数量
        indexVo.setTodayContractNum(contractMapper.getTodayContractNum(today, username));//今日合同数量
        indexVo.setTodaySalesAmount(contractMapper.getTodaySalesAmount(today, username));//今日销售金额
        indexVo.setCluesNum(clueMapper.getCountClueNum(beginCreatTime,endCreatetime,username));//线索数量
        indexVo.setBusinessNum(businessMapper.getCountBusinessNum(beginCreatTime,endCreatetime,username));//商机数量
        indexVo.setContractNum(contractMapper.getCountContractNum(beginCreatTime,endCreatetime,username));//合同数量
        indexVo.setSalesAmount(contractMapper.getCountSalesAmount(beginCreatTime,endCreatetime,username));//金额数量

        return indexVo;
    }
}